name: "build"
on:
  push:
    paths-ignore:
      - '**/*.md'
  pull_request:
    paths-ignore:
      - '**/*.md'

permissions:
  contents: write

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup JDK 11
        uses: actions/setup-java@v3
        with:
          distribution: 'adopt'
          java-version: '11'

      - name: JNI Download For Windows
        uses: bettermarks/action-artifact-download@0.3.0
        with:
          repo: cssxsh/t544_enc
          token: ${{ secrets.GITHUB_TOKEN }}
          artifact_name: push-build-windows

      - name: JNI Download For Linux
        uses: bettermarks/action-artifact-download@0.3.0
        with:
          repo: cssxsh/t544_enc
          token: ${{ secrets.GITHUB_TOKEN }}
          artifact_name: push-build-linux

      - name: JNI Download For Android
        uses: bettermarks/action-artifact-download@0.3.0
        with:
          repo: cssxsh/t544_enc
          token: ${{ secrets.GITHUB_TOKEN }}
          artifact_name: push-build-android

      - name: JNI Download For MacOS
        uses: bettermarks/action-artifact-download@0.3.0
        with:
          repo: cssxsh/t544_enc
          token: ${{ secrets.GITHUB_TOKEN }}
          artifact_name: push-build-macos

      - name: Unzip Artifact
        run: |
          mkdir -p src/main/resources/xyz/cssxsh/mirai/tool
          unzip push-build-windows -d src/main/resources/xyz/cssxsh/mirai/tool
          unzip push-build-linux -d src/main/resources/xyz/cssxsh/mirai/tool
          unzip push-build-android -d src/main/resources/xyz/cssxsh/mirai/tool
          unzip push-build-macos -d src/main/resources/xyz/cssxsh/mirai/tool

      - name: chmod -R 777 gradlew
        run: chmod -R 777 gradlew

      - name: Check
        run: ./gradlew Check

      - name: BuildPlugin
        run: ./gradlew buildPlugin

      - name: UploadPlugin
        uses: actions/upload-artifact@v3
        with:
          name: build
          path: build/mirai/*

      - name: CopyConsoleRuntime
        run: ./gradlew copyConsoleRuntime

      - name: UploadConsoleRuntime
        uses: actions/upload-artifact@v3
        with:
          name: console-runtime
          path: run/console

      - name: Release
        if: startsWith(github.ref, 'refs/tags/')
        uses: softprops/action-gh-release@v1
        with:
          files: build/mirai/*
          generate_release_notes: true